import axios from 'axios'
import cookie from "js-cookie";

const request = axios.create({
    // baseURL: 'https://apresunday.online/api',
    // baseURL: 'http://47.116.203.76:8080',
    baseURL: 'http://localhost:8080',
    // baseURL: 'http://8.134.216.53:8080',
    // baseURL: 'http://8.134.203.248:8080',
    timeout: 5000
})

// http request 拦截器
//每次发送请求都会使用这个拦截器
request.interceptors.request.use(
    config => {
        //debugger
        //如果从cookie中拿到analysis_token的值，则把它放入到http的header头的token中
        if (cookie.get('analysis_token')) {
            config.headers['token'] = cookie.get('analysis_token');
        } else {
            console.log("no token")
        }
        return config
    },
    err => {
        return Promise.reject(err);
    }
)

// axios请求拦截器
request.interceptors.request.use(config => {
    return config
}, e => Promise.reject(e))

// axios响应式拦截器
request.interceptors.response.use(res => res.data, e => {
    return Promise.reject(e)
})

export default request